#include <Arduino.h>
#include "wifi_ctrl.h"
#include "button.h"
#include "menu_ctrl.h"
#include "watchdog.h"
#include "aliyun.h"

void setup() 
{
  // put your setup code here, to run once:
  Serial.begin(115200);
  delay(10);

  Serial.printf("ESP32 HEAP %d\r\n", esp_get_free_heap_size());

  WiFi_Setup();

  Serial.printf("ESP32 HEAP %d\r\n", esp_get_free_heap_size());

  button_Init();

  Serial.printf("ESP32 HEAP %d\r\n", esp_get_free_heap_size());

  Watchdog_Init();

  Serial.println("loop start");
}

void loop() 
{
  // put your main code here, to run repeatedly:
  feed_dog();

  uint8_t button_state = get_button_state();
  if(button_state != 0)
  {
    Serial.printf("ESP32 HEAP1 %d\r\n", esp_get_free_heap_size());
    Serial.printf("button %d\r\n", button_state);
  }

  menu_proc(button_state);

  WiFi_Loop();

  client.loop();

  feed_dog();
}